package ar.com.ctrln.persistence.dao.participante;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import ar.com.ctrln.persistence.dao.AbstractHibernateDao;
import ar.com.ctrln.persistence.model.evento.Participante;

@Repository("participanteDao")
public class HibernateParcipanteDao extends AbstractHibernateDao<Participante>
		implements ParticipanteDao {

	@Override
	@Transactional(readOnly = true)
	public Set<Participante> getParticipantes(long idEvento) {
		Query q = getSession().createQuery(
				"Select e.participantes from EventoCalendario e where e.id =?");
		q.setParameter(0, idEvento);
		@SuppressWarnings("unchecked")
		Collection<Participante> resultado = q.list();
		Set<Participante> set = new HashSet<Participante>();
		for (Participante participante : resultado) {
			Hibernate.initialize(participante.getContacto());
			set.add(participante);
		}
		return set;
	}
}
